/*
 * @Author: wurangkun
 * @Date: 2024-05-21 10:48:43
 * @LastEditTime: 2024-05-22 10:31:19
 * @LastEditors: wurangkun
 * @FilePath: \flutter_example\lib\common\ThemeModel.dart
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter_example/common/global.dart';
import 'package:flutter_example/common/ProfileChangeNotifier.dart';

class ThemeModel extends ProfileChangeNotifier {
  // 获取当前主题，如果为设置主题，则默认使用蓝色主题
  MaterialColor get theme => Global.themes
      .firstWhere((e) => e.value == profile.theme, orElse: () => Colors.blue);

  // 主题改变后，通知其依赖项，新主题会立即生效
  set theme(ColorSwatch color) {
    if (color != theme) {
      profile.theme = color[500]!.value;
      notifyListeners();
    }
  }
}
